#include <nxos.h>

#define MAX_CMD_LEN 1024

NX_PRIVATE char cmdBuf[MAX_CMD_LEN];

NX_Error PowerBoxBuiltinStart(int argc, char *argv[], char * env)
{
    NX_Error err;

    if (argc >= 2)
    {
        if (NX_CmdToBuf(cmdBuf, MAX_CMD_LEN, &argv[1]) < 0)
        {
            NX_Printf("start: cmd to buf error!\n");
            return NX_ERROR;
        }

        NX_ProcessLaunch(argv[1], NX_THREAD_CREATE_NORMAL, NX_NULL, cmdBuf, env);
        err = NX_ErrorGet();
        if (err != NX_EOK)
        {
            NX_Printf("start: launch app `%s` failed with err %d/%s\n", argv[1], err, NX_ErrorToString(err));
            return err;
        }
        NX_ThreadSleep(10);
    }
    else
    {
        NX_Printf("Usage:\n  start appname [args, ...]\n");
    }
    return NX_EOK;
}
